package servlet.listenerServlet;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

@WebServlet(name = "ContextAttributeServlet", value = "/contextAttr")
public class ContextAttributeServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {


        ServletContext context = request.getServletContext();

        //context添加属性
        context.setAttribute("name","tom");
        //因为key相同，所以是修改属性
        context.setAttribute("name","jerry");
        //移除属性
        context.removeAttribute("name");

    }
}
